//
//  HXIflyJobRecordTableViewController.m
//  KD
//
//  Created by GaoFei on 16/7/8.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXIflyJobRecordTableViewController.h"

#import "HXGroupListTableViewCell.h"
#import "HXGroupJobTableViewController.h"//工作汇报

@interface HXIflyJobRecordTableViewController ()
@property (nonatomic,strong) NSMutableArray *dataArray;

@end

static NSString * identifierCell = @"identifierCell";

@implementation HXIflyJobRecordTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"汇报群组";
    
    [self getCompanyGroupList];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)getCompanyGroupList {
    
    [SVProgressHUD showWithStatus:@"正在加载..."];
    
    [NetworkAPI getJoinGroupsWithSuccess:^(HXGetJoinGroupModel *result) {
        if ([result.code isEqualToString:@"200"]) {
            [SVProgressHUD dismiss];
            [self.dataArray addObjectsFromArray:result.result];
            
            [self.tableView reloadData];
        }
    } failure:^(NSError *err) {
        
        [SVProgressHUD showErrorWithStatus:@"网络错误!"];
        
    }];
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
////#warning Incomplete implementation, return the number of sections
//    return 1;
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HXGroupListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierCell];
    
    HXGetJoinGroupListModel * data = self.dataArray[indexPath.row];
    
    cell.data = data;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 56.f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HXGetJoinGroupListModel * data = self.dataArray[indexPath.row];

    HXGroupJobTableViewController * workReportVc = [[HXGroupJobTableViewController alloc] initWithGroupId:data.GroupID];
    
    [self.navigationController pushViewController:workReportVc animated:YES];
}

//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//
//    return [NSString stringWithFormat:@"我加入的小组(%ld)",self.dataArray.count];
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//
//    return 30.f;
//}

#pragma mark - 懒加载
-(NSMutableArray *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}

@end
